﻿using System;
using System.Xml.Serialization;
using MergeTI.TiEntityObjects;
using TI;
using TI_EntityLib.TiEntityObjects;
using TiEntityObject.Common;
using TiPort.TiEntityObjects;

namespace TiEntityObject.Protocol
{
    public class Protocol : MongoEntity, IDbRootObject 
    {
        [XmlElement("notificationNumber")]
        public string NotificationNumber { get; set; }

        [XmlElement("protocolNumber")]
        public string ProtocolNumber { get; set; }

        public string Key { get { return ProtocolNumber; } }

        [XmlElement("foundationProtocolNumber")]
        public string FoundationProtocolNumber { get; set; }

        [XmlElement("parentProtocolNumber")]
        public string parentProtocolNumber { get; set; }

        [XmlElement("versionNumber")]
        public string versionNumber { get; set; }

        [XmlElement("documentMetas")]
        [LinkObjectAttribute(ChildFieldName = "NotificationID", IsCollection = true, IsPartialObject = true, ParentFieldName = "ID")]
        public ProtocolDocumentMetas DocumentMetas { get; set; }


        [XmlElement("protocolLots")]
        [LinkObjectAttribute(ChildFieldName = "ProtocolNumber", IsCollection = true, IsPartialObject = true, ParentFieldName = "ProtocolNumber")]
        public ProtocolLots Lots { get; set; }        
        
        [XmlElement("commission")]
        [LinkObjectAttribute(ChildFieldName = "ProtocolNumber", IsPartialObject = true, ParentFieldName = "ProtocolNumber")]
        public ProtocolCommission ProtocolCommission{ get; set; }

        [XmlElement("printForm")]
        [LinkObjectAttribute(ChildFieldName = "OwnerID", IsPartialObject = true, ParentFieldName = "ID")]
        public CommonPrintForm  PrintForm { get; set; }
        
        [XmlElement("place")]
        public string Place { get; set; }
        
        [XmlElement("protocolDate")]
        public DateTime ProtocolDate { get; set; }
        public long iProtocolDate { get { return Helper.Time.GetDateInMS(ProtocolDate); } }

        [XmlElement("signDate")]
        public DateTime SignDate { get; set; }
        public long iSignDate { get { return Helper.Time.GetDateInMS(SignDate); } }

        [XmlElement("publishDate")]
        public DateTime PublishDate { get; set; }
        public long iPublishDate { get { return Helper.Time.GetDateInMS(PublishDate); } }

        [XmlElement("modification")]
        public ProtocolModification Modification { get; set; }
        
        [XmlElement("href")]
        public string href { get; set; }        

        public DateTime LastUpdateDate
        {
            get
            {
                return DateTime.Now;
            }
            set
            {
                ;
            }
        }

        public string FileName{get;set;}

        public string ObjectType { get; set; }


      
        #region IDbRootObject Members

        public override string GetAsJson()
        {
            return Helper.Json<Protocol>.NewtonSerializeObject(this);
        }

        public long iFileDate { get; set; }

        public override  string GetInsertScript()
        {
            string v = GetAsJson();
            return "mergeProtocol(" + v + ")";
        }
        #endregion


        #region IDbRootObject Members


        public TiEntityClass Class
        {
            get { return TiEntityClass.Pharm ; }
        }

        #endregion


        string IDbRootObject.ObjectType
        {
            get;
            set;
        }


        public long iTransportDay
        {
            get;
            set;
        }
    }
}
